﻿sampler2D Texture1Sampler : register(S0);

float2 Direction : register(C0);

float4 DdxDdy : register(C1);

// http://dev.theomader.com/gaussian-kernel-calculator/
static const float HalfWidth = 80;
static const float poisson[161] =
{
	0.004411,0.004466,0.004521,0.004576,0.004631,0.004686,0.004741,0.004796,0.004851,0.004905,
	0.004959,0.005014,0.005067,0.005121,0.005175,0.005228,0.005281,0.005334,0.005386,0.005438,
	0.00549,0.005541,0.005592,0.005642,0.005692,0.005742,0.005791,0.005839,0.005888,0.005935,
	0.005982,0.006029,0.006074,0.00612,0.006164,0.006208,0.006252,0.006294,0.006336,0.006377,
	0.006418,0.006458,0.006497,0.006535,0.006572,0.006609,0.006644,0.006679,0.006713,0.006746,
	0.006779,0.00681,0.00684,0.00687,0.006898,0.006926,0.006952,0.006978,0.007003,0.007026,
	0.007049,0.00707,0.007091,0.00711,0.007128,0.007146,0.007162,0.007177,0.007191,0.007204,
	0.007216,0.007227,0.007236,0.007245,0.007252,0.007258,0.007263,0.007267,0.00727,0.007272,
	0.007272,
	0.007272,0.00727,0.007267,0.007263,0.007258,0.007252,0.007245,0.007236,0.007227,0.007216,
	0.007204,0.007191,0.007177,0.007162,0.007146,0.007128,0.00711,0.007091,0.00707,0.007049,
	0.007026,0.007003,0.006978,0.006952,0.006926,0.006898,0.00687,0.00684,0.00681,0.006779,
	0.006746,0.006713,0.006679,0.006644,0.006609,0.006572,0.006535,0.006497,0.006458,0.006418,
	0.006377,0.006336,0.006294,0.006252,0.006208,0.006164,0.00612,0.006074,0.006029,0.005982,
	0.005935,0.005888,0.005839,0.005791,0.005742,0.005692,0.005642,0.005592,0.005541,0.00549,
	0.005438,0.005386,0.005334,0.005281,0.005228,0.005175,0.005121,0.005067,0.005014,0.004959,
	0.004905,0.004851,0.004796,0.004741,0.004686,0.004631,0.004576,0.004521,0.004466,0.004411
};

float4 main(float2 uv : TEXCOORD) : COLOR
{
	float4 color = { 0, 0, 0, 1 };

for (int delta = -HalfWidth; delta <= HalfWidth; delta++)
{
	float2 coord;
	coord.x = uv.x + delta * DdxDdy.x * Direction.x;
	coord.y = uv.y + delta * DdxDdy.w * Direction.y;
	coord = saturate(coord);

	// Sample pixel
	color += tex2D(Texture1Sampler, coord) * poisson[delta + HalfWidth];
}

return(color);
}


